function ExcCalc($VAL) {
	
	$InAmount = document.ExcInvoice.Amount.value;
	$OutAmount = document.ExcInvoice.OUTVALUE.value;

	$InvType = document.ExcInvoice.operation_type.value;
	$ExcRATE = document.ExcInvoice.rate.value;

if ($InvType == 1) {

	if ($VAL == 1) {
		document.ExcInvoice.OUTVALUE.value = ($InAmount*$ExcRATE).toFixed(2);
		document.ExcInvoice.payed.value = ($InAmount*$ExcRATE).toFixed(2);

	document.ExcInvoice.delivered.value = ($InAmount*$ExcRATE).toFixed(2);
	document.ExcInvoice.acerto.value = 0;
	}
	if ($VAL == 2) {
		document.ExcInvoice.Amount.value = ($OutAmount/$ExcRATE).toFixed(2);
		document.ExcInvoice.payed.value = $OutAmount;

	document.ExcInvoice.delivered.value = $OutAmount;
	document.ExcInvoice.acerto.value = 0;
		
	}	

} else {

	if ($VAL == 1) {
		document.ExcInvoice.OUTVALUE.value = ($InAmount/$ExcRATE).toFixed(2);
		document.ExcInvoice.payed.value = ($InAmount/$ExcRATE).toFixed(2);

	document.ExcInvoice.delivered.value = ($InAmount/$ExcRATE).toFixed(2);
	document.ExcInvoice.acerto.value = 0;
	}
	if ($VAL == 2) {
		document.ExcInvoice.Amount.value = ($OutAmount*$ExcRATE).toFixed(2);
		document.ExcInvoice.payed.value = $OutAmount;

	document.ExcInvoice.delivered.value = $OutAmount;
	document.ExcInvoice.acerto.value = 0;
	}

}

}
function ExcExe($VAL) {
	
	$InAmount = document.ExchangeInvoice.Amount.value;
	$OutAmount = document.ExchangeInvoice.OUTVALUE.value;

	$InvType = document.ExchangeInvoice.operation_type.value;
	$ExcRATE = document.ExchangeInvoice.rate.value;

if ($InvType == 1) {

	if ($VAL == 1) {
		document.ExchangeInvoice.OUTVALUE.value = ($InAmount*$ExcRATE).toFixed(2);
		document.ExchangeInvoice.payed.value = ($InAmount*$ExcRATE).toFixed(2);

	document.ExchangeInvoice.delivered.value = ($InAmount*$ExcRATE).toFixed(2);
	document.ExchangeInvoice.acerto.value = 0;
	}
	if ($VAL == 2) {
		document.ExchangeInvoice.Amount.value = ($OutAmount/$ExcRATE).toFixed(2);
		document.ExchangeInvoice.payed.value = $OutAmount;

	document.ExchangeInvoice.delivered.value = $OutAmount;
	document.ExchangeInvoice.acerto.value = 0;
		
	}	

} else {

	if ($VAL == 1) {
		document.ExchangeInvoice.OUTVALUE.value = ($InAmount/$ExcRATE).toFixed(2);
		document.ExchangeInvoice.payed.value = ($InAmount/$ExcRATE).toFixed(2);

	document.ExchangeInvoice.delivered.value = ($InAmount/$ExcRATE).toFixed(2);
	document.ExchangeInvoice.acerto.value = 0;
	}
	if ($VAL == 2) {
		document.ExchangeInvoice.Amount.value = ($OutAmount*$ExcRATE).toFixed(2);
		document.ExchangeInvoice.payed.value = $OutAmount;

	document.ExchangeInvoice.delivered.value = $OutAmount;
	document.ExchangeInvoice.acerto.value = 0;
	}

}

}
function VerifyCAX() {
	$Limit = document.ExcInvoice.ExcCAX.value;
	$Amount = document.ExcInvoice.TmpAmount.value;

	if ($Amount == $Limit) {
	document.ExcInvoice.TmpAmount.value = $Limit;
	}

}